Skip to content

fix: harden MCP server auth, CORS, and request size limits - #607

Merged
ariskemper merged 5 commits into
mainfrom
security/h18-h19-m26-mcp-hardening
Mar 21, 2026
Merged

fix: harden MCP server auth, CORS, and request size limits#607
ariskemper merged 5 commits into
mainfrom
security/h18-h19-m26-mcp-hardening

Conversation

@ariskemper

@ariskemper ariskemper commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • (Auth): Log warning when no auth configured; reject requests when bearer auth has no validate function
  • (CORS): Match request Origin against full origins array instead of only origins[0]; require explicit origins when CORS enabled (no "*" default)
  • (Size limit): Add 1MB request body size limit with Content-Length header fast-path and body text length fallback

Test plan

  • Bearer auth without validate function rejects all requests (401)
  • Bearer auth without Authorization header rejects (401)
  • Bearer auth with valid token accepts request (200)
  • Bearer auth with invalid token rejects (401)
  • Request with Content-Length > 1MB rejected (413 fast path)
  • Request with body > 1MB rejected even without Content-Length (413 fallback)
  • Request within 1MB limit accepted (200)
  • CORS headers set when request Origin matches configured origins
  • No CORS headers when request Origin does not match
  • No CORS headers when no origins configured
  • No CORS headers when CORS is disabled
  • CORS headers included on POST responses when Origin matches
  • MCP server logs warning on startup when auth is not configured
  • All 18 tests passing

- Log warning when MCP server has no auth configured
- Reject all requests when bearer auth lacks a validate function
- Match CORS Origin against full origins array instead of only first entry
- Require explicit origins (no "*" default) when CORS enabled
- Add 1MB request body size limit before JSON parsing

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01cac11faf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mcp/server.ts
Comment thread src/mcp/server.ts
@ariskemper
ariskemper marked this pull request as draft March 10, 2026 20:29
@ariskemper ariskemper changed the title fix: harden MCP server auth, CORS, and request size limits (H18+H19+M26) fix: harden MCP server auth, CORS, and request size limits Mar 21, 2026
- Replace parseInt with Number() for cleaner NaN handling
- Add bearer auth tests: missing validate, missing header, valid/invalid token
- Add body size limit tests: Content-Length fast path, body fallback, within limit
- Add CORS tests: matching origin, non-matching origin, no origins, disabled, POST response
@ariskemper
ariskemper marked this pull request as ready for review March 21, 2026 15:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6a8e7b2d0a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mcp/server.ts
Without Vary: Origin, shared caches/CDNs can serve a response cached
for one origin to requests from a different origin, causing CORS failures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant